//
//  NodeAddController.m
//  Exam11-3
//
//  Created by 孙晓晔 on 2017/4/16.
//  Copyright © 2017年 孙晓晔. All rights reserved.
//

#import "NoteAddController.h"

@interface NoteAddController ()
@property (weak, nonatomic) IBOutlet UITextView *content;

@end

@implementation NoteAddController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)save:(UIBarButtonItem *)sender {
    
    if (self.content.text.length == 0) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"内容不能为空，请重新输入" preferredStyle: UIAlertControllerStyleAlert];
        
        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
        }]];
        
        [self presentViewController:alert animated:true completion:nil];
        
        return;
    }
    
    // 关闭当前视图
    [self.navigationController popViewControllerAnimated:YES];
    
    // 代理传值
    Note *note = [[Note alloc]init];
    
    note.content = self.content.text;

    [self.delegate addNote:self note:note];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
